Build an IdempotencyInterceptor that reads the Idempotency-Key request header, checks a cache for a stored response, and returns it if found — short-circuiting the handler. On the first request, let the handler run and store the response in cache with tap(). Fire-and-forget on cache writes so the response is never delayed.
The Idempotency-Key header must be unique per logical operation — clients generate it (e.g. UUID v4).
Cache the full response object — replay must return the exact same response body and status.
Set Idempotency-Replayed: true header on replayed responses so clients can detect duplicates.
Only apply to mutating methods (POST, PUT, PATCH) — GET is already idempotent by definition.
Use a distributed cache (Redis) in production — in-memory cache breaks on multi-instance deployments.
We have a NestJS controller that creates an order via POST /orders. How would you add support for an idempotency key so that if the client retries the same request, only one order is created?
If a client sends the same idempotency key twice within a minute, what should your service return, and how would you implement that logic?
Where would you store the idempotency key and its result in a typical NestJS app, and why?
You notice duplicate orders are still being created after adding an idempotency interceptor. Walk me through how you would debug the issue.
Explain the trade‑offs between storing idempotency keys in Redis versus a relational database in a NestJS microservice.
How would you handle expiration of idempotency keys for a high‑traffic payment endpoint, and what changes would you make to the NestJS middleware?
Design a reusable idempotency solution that works across multiple NestJS modules and can be toggled per route. What components would you create and how would they interact?
Consider a scenario where the downstream service fails after you have recorded the idempotency key. How would you ensure consistency and avoid lost updates?
What performance implications does checking idempotency keys have at scale, and how would you mitigate them in a NestJS application serving thousands of requests per second?
Your organization is migrating legacy monolith endpoints to a new NestJS platform. How would you introduce idempotency handling without breaking existing clients, and what governance processes would you put in place?
Across several teams, some services use Redis and others use PostgreSQL for idempotency storage. How would you standardize the approach and what architectural guidelines would you propose?
If you need to guarantee exactly‑once processing across distributed services, how does the idempotency‑key pattern fit, and what additional mechanisms would you combine with NestJS to achieve that?